package com.app.configuration;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @author 王鑫
 * @create 2020 -11 -23 14:41
 * 消息生产者消息确认
 */
@Configuration
public class ProducerConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback {

    @Autowired
    RabbitTemplate rabbitTemplate;


    //初始化方法注解
    @PostConstruct
    public void setUp() {
        rabbitTemplate.setConfirmCallback(this);
        rabbitTemplate.setReturnCallback(this);
    }

    //confirm消息确认
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        System.out.println("Confirm:" + ack);
    }

    //return的消息确认
    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        System.out.println("Return:" + message);
    }
}
